﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;

namespace AppFrameCmd
{
	class Program
	{
		static int Main(string[] args)
		{
			string channelUri = string.Format("ipc://{0}/{1}", YGame.Base.IpcCommand.ChannelName,"Server");
			IpcChannel channel = new IpcChannel();
			ChannelServices.RegisterChannel(channel, false);
			WellKnownClientTypeEntry remotEntry = new WellKnownClientTypeEntry(typeof(YGame.Base.IpcCommand), channelUri);
			RemotingConfiguration.RegisterWellKnownClientType(remotEntry);

			YGame.Base.IpcCommand iCmd = new YGame.Base.IpcCommand();
			Dictionary<string, string> serverArgs = new Dictionary<string, string>();
			foreach (var item in args)
			{
				string key="", value="";
				string[] keyvalue = item.Split('=');

				if (keyvalue.Length>=1)
				{
					key = keyvalue[0];
				}
				if (keyvalue.Length >= 2)
				{
					value = keyvalue[1];
				}
				serverArgs[key] = value;
			}
			Console.WriteLine("IpcCommand call: {0}", channelUri);
			try
			{
				int ret = iCmd.Execute(serverArgs);
				Console.WriteLine("IpcCommand return: {0}", ret);
				return ret;
			}
			catch (Exception ex)
			{
				Console.WriteLine("IpcCommand false: {0}\r\n", ex.Message, ex.StackTrace);
				return 1;
			}
		}
	}
}


